package com.ad.pet.app.main;

import android.app.Activity;

import com.ad.pet.api.ApiService;
import com.ad.pet.app.RxDisposable;
import com.ad.pet.common.data.http.AppSubscriber;
import com.ad.pet.common.structure.mvp.AbsBasePresenter;
import com.ad.pet.models.remote.CommList;
import com.ad.pet.models.remote.User;
import com.ad.pet.models.remote.home.Cate;
import com.ad.pet.models.remote.home.floor.MainFloor;
import com.ad.pet.models.remote.home.floor.PopNewRegist;

import java.util.List;

import javax.inject.Inject;

/**
 * Created by SEELE on 2018/12/29.
 */
public class HomeContentPresenter extends AbsBasePresenter implements HomeContentContract.Presenter{
    private ApiService mApiService;
    private HomeContentContract.View mView;

    private Activity mActivity;

    private RxDisposable mRxDisposable;

    @Inject
    public HomeContentPresenter(ApiService apiService,
                                Activity activity, RxDisposable rxDisposable) {
        mApiService = apiService;
        mActivity = activity;
        mRxDisposable = rxDisposable;
    }

    @Override
    public void onCreate(HomeContentContract.View view) {
        this.mView = view;
    }


    @Override
    public void onDestroy() {
        if (mRxDisposable != null)
            mRxDisposable.clear();
        if (mActivity != null) mActivity = null;
        mView = null;
    }


    @Override
    public void getTopBar() {
        mRxDisposable.add(mApiService.top_bar()
                .subscribe(new AppSubscriber<CommList<List<Cate>>>(mView) {
                    @Override
                    public void next(CommList<List<Cate>> list) {

                        mView.getTopBarSuccess(list.getList());
                    }
                }));
    }

    @Override
    public void getTopBarMenu() {
        mRxDisposable.add(mApiService.top_bar_menu()
                .subscribe(new AppSubscriber<CommList<List<Cate>>>(mView) {
                    @Override
                    public void next(CommList<List<Cate>> list) {

                        mView.getTopBarMenuSucces(list.getList());
                    }
                }));
    }

    @Override
    public void getMessagesNumber() {
        mRxDisposable.add(mApiService.getReadMessageNumber()
                .subscribe(new AppSubscriber<User>(mView) {
                    @Override
                    public void next(User list) {
                        mView.getMessageNumberSuccess(list.getNum());
                    }
                }));
    }

    @Override
    public void getHomeFloor() {
        mRxDisposable.add(mApiService.getHomeFloorData()
                .subscribe(new AppSubscriber<CommList<List<MainFloor>>>(mView) {
                    @Override
                    public void next(CommList<List<MainFloor>> list) {
                        mView.getHomeFloorSuccess(list.getList());
                    }
                }));
    }

    @Override
    public void get_check_is_sign_home() {
        mRxDisposable.add(mApiService.check_is_sign_home()
                .subscribe(new AppSubscriber<PopNewRegist>(mView) {
                    @Override
                    public void next(PopNewRegist list) {
                        mView.get_check_is_sign_homeSuccess(list);
                    }
                }));
    }

    @Override
    public void register_sign_home() {
        mRxDisposable.add(mApiService.register_sign_home()
                .subscribe(new AppSubscriber<PopNewRegist>(mView) {
                    @Override
                    public void next(PopNewRegist list) {
                        mView.register_sign_homeSuccess(list);
                    }
                }));
    }
}
